<?php

	require_once(APPPATH . 'controllers/base_controllers/base_validation_controller.php');
	
	class New_member_sign_up_validation extends Base_validation_controller
	{
		
		public function __construct()
		{
			parent::__construct();
			
			$this->load->library('validation');
		}
		
		
		public function validate_step1()
		{
			$rules['userName'] = "trim|required";
			$rules['password'] = "trim|required|min_length[6]";
			$rules['firstName']	= "trim|required";
			$rules['lastName'] = "trim|required";
			$rules['gender'] = "trim|required";
			$rules['primaryEmail'] = "trim|required|valid_email";
			$rules['homePhoneNumber'] = "trim|required|callback_valid_phone_check";
			$rules['mobilePhoneNumber'] = "trim|callback_valid_phone_check";
			$rules['dateJoinedCmb'] = "trim|callback_valid_date_check";
			$rules['homeAddress1'] = "trim|required";
			$rules['city'] = "trim|required";
			$rules['state'] = "trim|required";
			$rules['zipCode'] = "trim|required|callback_valid_zip_code_check";
			$rules['centerForSatsang'] = "trim|required";
			$rules['preferredSatsangSession'] = "trim|required";
			$rules['numberOfChildrenAttendingBalvihar'] = "trim|required";
			
			$this->validation->set_rules($rules);
			
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_step1( $this->validation->error_string ) );
			}
			
			die;
		}
		
		
		public function validate_step2()
		{
			$rules['userName'] = "trim|required";
			$rules['password'] = "trim|required|min_length[6]";
			$rules['firstName']	= "trim|required";
			$rules['lastName'] = "trim|required";
			$rules['gender'] = "trim|required";
			$rules['primaryEmail'] = "trim|required|valid_email";
			$rules['homePhoneNumber'] = "trim|required|callback_valid_phone_check";
			$rules['mobilePhoneNumber'] = "trim|callback_valid_phone_check";
			$rules['dateJoinedCmb'] = "trim|callback_valid_date_check";
			
			$this->validation->set_rules($rules);
			
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_step2( $this->validation->error_string ) );
			}
			
			die;
		}
		
		
		public function validate_step3()
		{
			$rules['firstName']	= "trim|required";
			$rules['lastName'] = "trim|required";
			$rules['gender'] = "trim|required";
			$rules['primaryEmail'] = "trim|valid_email";
			$rules['homePhoneNumber'] = "trim|callback_valid_phone_check";
			$rules['birthDate'] = "trim|required|callback_valid_date_check";
			$rules['grade'] = "trim|required";
			$rules['centerForBalvihar'] = "trim|required";
			if( $this->input->post('attendLanguageClasses') == 'yes' )
			{ 
				$rules['language'] = "trim|required";
				$rules['languageSession'] = "trim|required"; 
			}
			
			
			$this->validation->set_rules($rules);
			
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_step3( $this->validation->error_string ) );
			}
			
			die;
		}
		
		
		private function clean_validation_errors_for_step1( $valErrors )
		{
			$valErrors = str_replace("userName", "User Name", $valErrors);
			$valErrors = str_replace("password", "Password", $valErrors);
			$valErrors = str_replace("firstName", "First Name", $valErrors);
			$valErrors = str_replace("lastName", "Last Name", $valErrors);
			$valErrors = str_replace("gender", "Gender", $valErrors);
			$valErrors = str_replace("primaryEmail", "Primary Email", $valErrors);
			$valErrors = str_replace("homePhoneNumber", "Home Phone Number", $valErrors);
			$valErrors = str_replace("mobilePhoneNumber", "Mobile Phone Number", $valErrors);
			$valErrors = str_replace("dateJoinedCmb", "Date Joined CMB", $valErrors);
			$valErrors = str_replace("homeAddress1", "Home Address 1", $valErrors);
			$valErrors = str_replace("city", "City", $valErrors);
			$valErrors = str_replace("state", "State", $valErrors);
			$valErrors = str_replace("zipCode", "Zip Code", $valErrors);
			$valErrors = str_replace("centerForSatsang", "Center for Satsang", $valErrors);
			$valErrors = str_replace("preferredSatsangSession", "Preferred Satsang Session", $valErrors);
			$valErrors = str_replace("numberOfChildrenAttendingBalvihar", "Number of Children Attending Balvihar", $valErrors);
			
			return $valErrors;
		}
		
		
		private function clean_validation_errors_for_step2( $valErrors )
		{
			$valErrors = str_replace("userName", "Spouse User Name", $valErrors);
			$valErrors = str_replace("password", "Spouse Password", $valErrors);
			$valErrors = str_replace("firstName", "Spouse First Name", $valErrors);
			$valErrors = str_replace("lastName", "Spouse Last Name", $valErrors);
			$valErrors = str_replace("gender", "Spouse Gender", $valErrors);
			$valErrors = str_replace("primaryEmail", "Spouse Primary Email", $valErrors);
			$valErrors = str_replace("homePhoneNumber", "Spouse Home Phone Number", $valErrors);
			$valErrors = str_replace("mobilePhoneNumber", "Spouse Mobile Phone Number", $valErrors);
			$valErrors = str_replace("dateJoinedCmb", "Date Joined CMB", $valErrors);
			
			return $valErrors;
		}
		
		
		private function clean_validation_errors_for_step3( $valErrors )
		{
			$valErrors = str_replace("firstName", "Child First Name", $valErrors);
			$valErrors = str_replace("lastName", "Child Last Name", $valErrors);
			$valErrors = str_replace("gender", "Child Gender", $valErrors);
			$valErrors = str_replace("primaryEmail", "Child Primary Email", $valErrors);
			$valErrors = str_replace("homePhoneNumber", "Child Home Phone Number", $valErrors);
			$valErrors = str_replace("birthDate", "Child Birth Date", $valErrors);
			$valErrors = str_replace("grade", "Grade", $valErrors);
			$valErrors = str_replace("centerForBalvihar", "Center for Balvihar", $valErrors);
			$valErrors = str_replace("languageSession", "Language Session", $valErrors);
			$valErrors = str_replace("language", "Language", $valErrors);
			
			return $valErrors;
		}
	}

?>